package DynamicProxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class MainShop {
    public static void main(String[] args) {
        //目标类
        UsbShell usbShell = new UsbKingFactory();

        //增强对象
        InvocationHandler handler = new MyShellHandler(usbShell);

        //代理对象
        UsbShell proxy = (UsbShell) Proxy.newProxyInstance(usbShell.getClass().getClassLoader(),
                usbShell.getClass().getInterfaces(),handler);

        //通过代理执行目标方法
        float price = proxy.shell(1);
        float price2 = proxy.desc(100);
        System.out.println("通过代理类，得到的价格"+price);
        System.out.println("desc"+price2);
    }
}
